﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using WeifenLuo.WinFormsUI.Docking;

namespace BYManageInfoSystem
{
    public partial class Form_SJHuiLvTabMgr : DockContent
    {
        private DGBY.BLL.SJHuiLvTab m_bllSJHuiLvTab = new DGBY.BLL.SJHuiLvTab();
        private DGBY.BLL.BiZhiTab m_bllBiZhiTab = new DGBY.BLL.BiZhiTab();

        private int m_nSJHuiLvTabID = 0;

        public Form_SJHuiLvTabMgr()
        {
            InitializeComponent();
        }

        private void buttonModifyPort_Click(object sender, EventArgs e)
        {
            DGBY.Model.SJHuiLvTab modelSJHuiLvTab = m_bllSJHuiLvTab.GetModel(m_nSJHuiLvTabID);

            if (null == modelSJHuiLvTab)
            {
                DGBY.Model.SJHuiLvTab modelNewSJHuiLvTab = new DGBY.Model.SJHuiLvTab();
                modelNewSJHuiLvTab.SJHuiLv = Convert.ToDecimal(this.textSJHuiLv.Text);
                modelNewSJHuiLvTab.BiZhiTabID = Convert.ToInt32(this.comboBoxBiZhi.SelectedValue.ToString());

                m_nSJHuiLvTabID = m_bllSJHuiLvTab.Add(modelNewSJHuiLvTab);
            }
            else
            {
                modelSJHuiLvTab.SJHuiLv = Convert.ToDecimal(this.textSJHuiLv.Text);
                m_bllSJHuiLvTab.Update(modelSJHuiLvTab);

                Frm_Main.Log2DB(this.Text, "修改", this.comboBoxBiZhi.Text);
            }
            
            MessageBox.Show("数据修改成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }

        private void Form_DiscountMgr_Load(object sender, EventArgs e)
        {
            InitCombox();

            SetSJHuiLvValuebySelectedValue();
        }

        private void labelCoinUnit_Click(object sender, EventArgs e)
        {

        }

        private void comboBoxCoinUnit2_SelectedIndexChanged(object sender, EventArgs e)
        {
            SetSJHuiLvValuebySelectedValue();
        }

        private void InitCombox()
        {
            DataSet ds = m_bllBiZhiTab.GetList("");
            if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                this.comboBoxBiZhi.DataSource = ds.Tables[0];
                this.comboBoxBiZhi.DisplayMember = "币制名称";
                this.comboBoxBiZhi.ValueMember = "BiZhiTabID";
                this.comboBoxBiZhi.SelectedIndex = 0;
            }
        }

        private void SetSJHuiLvValuebySelectedValue()
        {
            try
            {
                string str = this.comboBoxBiZhi.SelectedValue.ToString();
                DataSet ds = m_bllSJHuiLvTab.GetList("BiZhiTabID = '" + str + "'");
                if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                {
                    this.textSJHuiLv.Text = ds.Tables[0].Rows[0]["SJHuiLv"].ToString();
                    m_nSJHuiLvTabID = Convert.ToInt32(ds.Tables[0].Rows[0]["SJHuiLvTabID"]);
                }
                else
                {
                    this.textSJHuiLv.Text = "";
                    m_nSJHuiLvTabID = 0;
                }
            }
            catch { }
        }

        private void groupBoxPort_Enter(object sender, EventArgs e)
        {

        }
    }
}


